package com.xuyuan.socket.mycase2;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.util.WebAppRootListener;


/**
 * 方式二：使用 ServerEndpoint方式创建 WebSocket端点
 *
 * @author xuyuan
 */
//@Configuration
//@EnableWebSocket
public class WebSocketConfig implements ServletContextInitializer {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.addListener(WebAppRootListener.class);
        servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", "131072");
        servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize", "131072");
    }
}
